home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / httpd_1.4-l / httpd_1.4-linux-diffs2
Encoding:
Text File  |  1995-05-23  |  4.3 KB  |  164 lines

  1. diff --recursive -u httpd_1.4-orig/src/Makefile httpd_1.4/src/Makefile
  2. --- httpd_1.4-orig/src/Makefile    Sun Apr 30 22:12:19 1995
  3. +++ httpd_1.4/src/Makefile    Tue May 23 11:24:28 1995
  4. @@ -16,8 +16,9 @@
  5.  # determine if it is a parsed file, use -DXBITHACK
  6.  # If you don't want to use the multiple child architecture, use -DNO_PASS
  7.  # 
  8. -CFLAGS= -O2  -g -DPEM_AUTH
  9. -#CFLAGS= -g -Wall -ansi -pedantic -DPEM_AUTH
  10. +# CFLAGS= -O2  -g -DPEM_AUTH
  11. +# CFLAGS= -g -Wall -ansi -pedantic -DPEM_AUTH
  12. +CFLAGS = -O2 -Wall
  13.  
  14.  # Place here any extra libraries you may need to link to. You
  15.  # shouldn't have to.
  16. @@ -53,7 +54,7 @@
  17.  # For Sequent
  18.  # AUX_CFLAGS= -DSEQUENT
  19.  # For Linux -m486 ONLY IF YOU HAVE 486 BINARY SUPPORT IN KERNEL
  20. -# AUX_CFLAGS= -DLINUX
  21. +AUX_CFLAGS= -DLINUX
  22.  # For NetBSD 1.0
  23.  # May not need -lcrypt if its included in your libc
  24.  # AUX_CFLAGS= -DNETBSD
  25. diff --recursive -u httpd_1.4-orig/src/http_ipc.c httpd_1.4/src/http_ipc.c
  26. --- httpd_1.4-orig/src/http_ipc.c    Fri Apr 21 09:03:34 1995
  27. +++ httpd_1.4/src/http_ipc.c    Tue May 23 11:24:28 1995
  28. @@ -281,4 +281,38 @@
  29.  
  30.  #endif
  31.  
  32. -#endif 
  33. +#ifdef FD_LINUX
  34. +
  35. +int pass_fd(int clifd, int fd) {
  36. +  char buf[128];
  37. +
  38. +  sprintf(buf, "/proc/%d/fd/%d", (int)getpid(), fd);
  39. +  if (write(clifd, buf, sizeof(buf)) < 0) {
  40. +    log_error("pass_fd: write failed");
  41. +    return(-1);
  42. +  }
  43. +  read(clifd, buf, 2); /* Wait for OK */
  44. +  return(0);
  45. +}
  46. +
  47. +int recv_fd(int servfd) {
  48. +  char buf[128];
  49. +  int fd;
  50. +
  51. +  if (read(servfd, buf, sizeof(buf)) != sizeof(buf)) {
  52. +    log_error("recv_fd: read failed");
  53. +    return(-1);
  54. +  }
  55. +  fd = open(buf, O_RDWR);
  56. +  (void) write(servfd, "OK", 2); /* Tell 'em we've aquired the fd */
  57. +  if (fd < 0) {
  58. +    log_error(strerror(errno));
  59. +    log_error(buf);
  60. +    log_error("recv_fd: open failed");
  61. +  }
  62. +  return(fd);
  63. +}
  64. +
  65. +#endif
  66. +
  67. +#endif
  68. diff --recursive -u httpd_1.4-orig/src/httpd.c httpd_1.4/src/httpd.c
  69. --- httpd_1.4-orig/src/httpd.c    Tue May  2 14:20:06 1995
  70. +++ httpd_1.4/src/httpd.c    Tue May 23 12:16:13 1995
  71. @@ -307,7 +307,9 @@
  72.      int x;
  73.      
  74.  /*    struct passwd* pwent; */
  75. -    
  76. +#ifdef LINUX
  77. +    static int switch_uid = 0;
  78. +#endif
  79.  
  80.      /* Only try to switch if we're running as root */
  81.      if(!getuid()) {
  82. @@ -316,8 +318,24 @@
  83.         /* Now, make absolutely certain we don't have any privileges
  84.          * except those mentioned in the configuration file. */
  85.          
  86. +#ifdef LINUX
  87. +       /*
  88. +        * This is very tricky, because we want to switch real
  89. +        * and effective UID while retaining a saved uid.
  90. +        * Don't change this unless you know what you're doing!
  91. +        */
  92. +
  93. +       /* First, make us set-uid. */
  94. +       if (setreuid(user_id, -1) == -1)
  95. +        die(CONF_ERROR,"unable to change uid",stdout);
  96. +       /* Saved uid is now 0. Reset effective uid. */
  97. +       if (seteuid(user_id) == -1)
  98. +        die(CONF_ERROR,"unable to change uid",stdout);
  99. +       switch_uid = 1;
  100. +#else
  101.         if (setuid(user_id) == -1)
  102.          die(CONF_ERROR,"unable to change uid",stdout);
  103. +#endif
  104.        standalone = 1;
  105.      } 
  106.  
  107. @@ -344,8 +362,25 @@
  108.      initialize_request();
  109.      dup2(parent_pipe,0);
  110.      dup2(parent_pipe,1);
  111. -    if ((csd = recv_fd(parent_pipe)) < 0) {
  112. +#ifdef LINUX
  113. +        /* Switch to root privilige temporarily */
  114. +        if (switch_uid && seteuid(0) < 0) {
  115. +          log_error("child error: seteuid(0)");
  116. +          goto fatal;
  117. +        }
  118. +#endif
  119. +    csd = recv_fd(parent_pipe);
  120. +#ifdef LINUX
  121. +        /* Give up priviliges. */
  122. +        if (switch_uid && seteuid(user_id) < 0) {
  123. +          standalone = 0;
  124. +          die(CONF_ERROR,"unable to change uid",stdout);
  125. +          goto fatal;
  126. +        }
  127. +#endif
  128. +    if (csd < 0) {
  129.        log_error("child error: recv_fd()");
  130. +fatal:
  131.        close(0);
  132.           close(1);
  133.        close(sd);
  134. @@ -610,7 +645,7 @@
  135.  extern char *optarg;
  136.  extern int optind;
  137.  
  138. -main(int argc, char *argv[])
  139. +int main(int argc, char *argv[])
  140.  {
  141.      int c;
  142.  
  143. diff --recursive -u httpd_1.4-orig/src/httpd.h httpd_1.4/src/httpd.h
  144. --- httpd_1.4-orig/src/httpd.h    Tue May  2 14:25:25 1995
  145. +++ httpd_1.4/src/httpd.h    Tue May 23 11:24:29 1995
  146. @@ -144,7 +144,7 @@
  147.  #define JMP_BUF jmp_buf
  148.  
  149.  #elif defined(LINUX)
  150. -#define NO_PASS
  151. +#define FD_LINUX
  152.  #undef BSD
  153.  #undef NO_KILLPG
  154.  #undef NO_SETSID
  155. @@ -295,7 +295,7 @@
  156.  #endif
  157.  
  158.  /* If we haven't set anything about file descriptor passing, set NO_PASS */
  159. -#if !defined(FD_BSD) && !defined(FD_SYSV) && !defined(NO_PASS)
  160. +#if !defined(FD_BSD) && !defined(FD_SYSV) && !defined(FD_LINUX) && !defined(NO_PASS)
  161.  #define NO_PASS
  162.  #endif
  163.  
  164.